<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">

<xi:include href="master.html" />

<head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
    <title py:if="news">Edit news | Yale Club Beijing</title>
    <title py:if="not news">Add news | Yale Club Beijing</title>
    <style type="text/css">
        #editnews{
            margin-top: 20px;
            border-spacing: 5px;
        }
        #editnews td{
            vertical-align: top;
        }
        #editnews tr td:first-child{
            width: 100px;
            font-weight: bold;
            font-size: 14px;
        }
        #newstitle, #newssummary, #newscontent{
            width: 900px;
        }
        #newscontent{
            height: 300px;
        }
    </style>
    <script type="text/javascript" src="/static/javascript/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
	tinyMCE.init({
		mode: "exact",
		elements: "newscontent",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js"
	});
</script>
<script type="text/javascript">
    //<![CDATA[
    window.onload = function(){
        $('newsform').addEvent('submit', function(){
            validate();
            return false;
        });
        $('newsdiscard').addEvent('click', function(){
            document.location = 'news';
        });
    }
    function validate(){
        if (!$("newstitle").value){
            alert("Title can not be empty.");
            return;
        }
        if (!$('newssummary').value){
            alert("Summary can not be empty.");
            return;
        }
        if (!tinyMCE.get('newscontent').getContent()){
            alert("Content can not be empty.");
            return;
        }
        $('newsform').submit();
    }
    //]]>
    </script>
</head>
<body>
<h1 py:if="news">Edit news</h1>
<h1 py:if="not news">Add news</h1>
<form id="newsform" method="post" action="addnews">
<table id="editnews">
    <tr><td>Title</td><td><input type="text" id="newstitle" name="title" value="${news.title if news else None}"/></td></tr>
    <tr><td>Summary</td><td><textarea id="newssummary" name="summary">${news.summary if news else None}</textarea></td></tr>
    <tr><td>Content</td><td><textarea class="tinymce" id="newscontent" name="content">${news.content if news else None}</textarea></td></tr>
    <tr><td></td><td><input type="submit" value="Save" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="newsdiscard" type="button" value="Discard" /></td></tr>
</table>
<input py:if="news" type="hidden" name="nid" value="${news.id}" />
</form>
</body>
</html>
